#include"Queue.h"


template<typename Queue_entry>
Queue<Queue_entry>::Queue()
{
	count = 0;
	rear = MAX_QUEUE - 1;
	front = 0;
}

template<typename Queue_entry>
bool Queue<Queue_entry>::empty()const
{
	return count == 0;
}

template<typename Queue_entry>
Error_code Queue<Queue_entry>::append(const Queue_entry& item)
{
	if (count >= MAX_QUEUE)
		return overflow;
	count++;
	rear = ((rear + 1) == MAX_QUEUE) ? 0 : (rear + 1);
	entry[rear] = item;
	return success;
}

template<typename Queue_entry>
Error_code Queue<Queue_entry>::serve()
{
	if (count <= 0)
		return underflow;
	count--;
	front = ((front + 1) == MAX_QUEUE) ? 0 : (front + 1);
	return success;
}

template<typename Queue_entry>
Error_code Queue<Queue_entry>::retrieve(Queue_entry& item)const
{
	if (count <= 0)
		return underflow;
	item = entry[front];
	return success;
}

template<typename Queue_entry>
bool Queue<Queue_entry>::full()const
{
	return count == MAX_QUEUE;
}

template<typename Queue_entry>
int Queue<Queue_entry>::size()const
{
	return count;
}

template<typename Queue_entry>
void Queue<Queue_entry>::clear()
{
	count = 0;
	rear = MAX_QUEUE - 1;
	front = 0;
}

template<typename Queue_entry>
Error_code Queue<Queue_entry>::serve_and_retrieve(Queue_entry& item)
{
	if (count <= 0)
		return underflow;
	count--;
	item = entry[front];
	front = ((front + 1) == MAX_QUEUE) ? 0 : (front + 1);
	return success;
}
